///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_IMAGE_FONT_CSCALEDFONT_H_
#define _BUOLA_IMAGE_FONT_CSCALEDFONT_H_

#include <buola/image/cfont.h>
#include <buola/image/cfontconfig.h>
#include <buola/mat/transformations.h>

#include <unordered_map>

#include <ft2build.h>
#include FT_FREETYPE_H

#include <buola/image/font/cfontface.h>
#include <buola/image/canyimage.h>

namespace buola { namespace img {

class CScaledFont
{
private:
    typedef std::unordered_map<TGlyphIndex,CScaledGlyph*> tGlyphCache;

    CScaledFont(CFontFace *pFace,const mat::C2DTransform &pFM,const mat::C2DTransform &pTM);

public:
    bool IsVertical();
    void FillGlyphInfo(CGlyphInfo &pG);

    const CFontMetrics &GetMetrics()    {   return mMetrics;    }

    const mat::C2DTransform &GetFontMatrix() {   return mFontMatrix; }

    CScaledGlyph *LookupGlyph(TGlyphIndex pGlyph,EGlyphData pData);

private:
    void InitScaledGlyph(CScaledGlyph *pGlyph,EGlyphData pData);
    img::CAnyImage *GetImageFromFTBitmap(FT_Bitmap *pBitmap,bool pOwnBuffer);

public:
    static CScaledFont *Create(CFontFace *pFace,const mat::C2DTransform &pFM,const mat::C2DTransform &pTM);

private:
    tGlyphCache mGlyphCache;
    CFontFace *mFontFace;
    CFTOptions mFTOptions;

    mat::C2DTransform mFontMatrix,mTransformMatrix,mScaleMatrix;

    CFontMetrics mFSMetrics; //in font space
    CFontMetrics mMetrics;

    double mMaxScale;
};

/*namespace img*/ } /*namespace buola*/ }

#endif
